<?php
namespace app\customer\controller;
use think\Db;
class Common extends Base{
    public function welcome(){
        $customer = Db::name('customer')->where('id',session('customer')['id'])->find();
        $products = Db::name('product')->where('cus_id',session('customer')['id'])->where('state',1)->select();
        $productfive = Db::name('product')->where('cus_id',session('customer')['id'])->where('state',1)->order('id desc')->limit(5)->select();
        $news = Db::name('news')->where('cus_id',session('customer')['id'])->where('state',1)->select();
        $newsfive = Db::name('news')->where('cus_id',session('customer')['id'])->where('state',1)->order('id desc')->limit(5)->select();
        $message = Db::name('message')->where('cus_id',session('customer')['id'])->where('state',1)->select();
        $messagefive = Db::name('message')->where('cus_id',session('customer')['id'])->where('state',1)->order('id desc')->limit(5)->select();
        $users = Db::name('users')->where('cus_id',session('customer')['id'])->select();
        $enlist = Db::name('enlist')->where('cus_id',session('customer')['id'])->select();
        $collect = Db::name('collect')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('users c', 'a.openid = c.openid','LEFT')->field('a.*,b.title,c.nickname')->where('a.cus_id',session('customer')['id'])->where('a.state',1)->select();
        $nmessage = Db::name('nmessage')->where('cus_id',session('customer')['id'])->where('state',1)->select();
        $nmessagefive = Db::name('nmessage')->alias('a')->join('users b', 'a.openid = b.openid','LEFT')->field('a.*,b.nickname')->where('a.cus_id',session('customer')['id'])->where('a.state',1)->order('a.id desc')->limit(5)->select();
        $nnews = Db::name('nnews')->where('cus_id',session('customer')['id'])->where('state',1)->select();
        $nnewsfive = Db::name('nnews')->where('cus_id',session('customer')['id'])->where('state',1)->order('id desc')->limit(5)->select();
        $today=date('Y-m-d',time());
        $yesterday=date('Y-m-d',time()-1*86400);
        $thirday=date('Y-m-d',time()-2*86400);
        $fouthday=date('Y-m-d',time()-3*86400);
        $frithday=date('Y-m-d',time()-4*86400);
        $sixthday=date('Y-m-d',time()-5*86400);
        $seventhday=date('Y-m-d',time()-6*86400);
        $todaynum=Db::name('actives')->where('cus_id',session('customer')['id'])->where('time','>',strtotime($today))->where('time','<',strtotime($today)+86400)->count();
        $yesterdaynum=Db::name('actives')->where('cus_id',session('customer')['id'])->where('time','>',strtotime($yesterday))->where('time','<',strtotime($yesterday)+86400)->count();
        $thirdaynum=Db::name('actives')->where('cus_id',session('customer')['id'])->where('time','>',strtotime($thirday))->where('time','<',strtotime($thirday)+86400)->count();
        $fouthdaynum=Db::name('actives')->where('cus_id',session('customer')['id'])->where('time','>',strtotime($fouthday))->where('time','<',strtotime($fouthday)+86400)->count();
        $frithdaynum=Db::name('actives')->where('cus_id',session('customer')['id'])->where('time','>',strtotime($frithday))->where('time','<',strtotime($frithday)+86400)->count();
        $sixthdaynum=Db::name('actives')->where('cus_id',session('customer')['id'])->where('time','>',strtotime($sixthday))->where('time','<',strtotime($sixthday)+86400)->count();
        $seventhdaynum=Db::name('actives')->where('cus_id',session('customer')['id'])->where('time','>',strtotime($seventhday))->where('time','<',strtotime($seventhday)+86400)->count();
        $this->assign('customer',$customer);
        $this->assign('products',$products);
        $this->assign('productfive',$productfive);
        $this->assign('news',$news);
        $this->assign('newsfive',$newsfive);
        $this->assign('message',$message);
        $this->assign('messagefive',$messagefive);
        $this->assign('nmessage',$nmessage);
        $this->assign('nmessagefive',$nmessagefive);
        $this->assign('users',$users);
        $this->assign('enlist',$enlist);
        $this->assign('collect',$collect);
        $this->assign('nnews',$nnews);
        $this->assign('nnewsfive',$nnewsfive);
        $this->assign('today',$today);
        $this->assign('yesterday',$yesterday);
        $this->assign('thirday',$thirday);
        $this->assign('fouthday',$fouthday);
        $this->assign('frithday',$frithday);
        $this->assign('sixthday',$sixthday);
        $this->assign('seventhday',$seventhday);
        $this->assign('todaynum',$todaynum);
        $this->assign('yesterdaynum',$yesterdaynum);
        $this->assign('thirdaynum',$thirdaynum);
        $this->assign('fouthdaynum',$fouthdaynum);
        $this->assign('frithdaynum',$frithdaynum);
        $this->assign('sixthdaynum',$sixthdaynum);
        $this->assign('seventhdaynum',$seventhdaynum);
        return $this->fetch();
    }
}
